package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-28 14:41
 **/
public class LeetCode5939 {

    public int[] getAverages(int[] nums, int k) {
        int len = nums.length;
        int[] res = new int[len];
        for (int i = 0; i < len; i++) {
            if (i - k < 0 || i + k >= len) {
                res[i] = -1;
            } else {
                long sum = nums[i];
                for (int j = 1; j <= k;j++) {
                    sum += (nums[i + j] + nums[i - j]);
                }
                res[i] = (int)(sum / (2 * k + 1));
            }
        }
        return res;
    }

}
